package cn.edu.jlu.grid.vjm;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;


public class Test {
	private static void print(Object obj) {
		System.out.println(obj);
	}
	public static void main(String[] args) {
		ServerSocket server = null;
		int port = 0;
		
		try {
			server = new ServerSocket(0);
			port = server.getLocalPort();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		print("Server start at: " + port);
		while(true) {
			try {
				Socket conn = server.accept();
				ObjectInputStream oin = new ObjectInputStream(conn.getInputStream());
				Object obj = oin.readObject();
				print("read object: " + obj);				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
}
